let fs = require("fs"); //加载fs模块
let user = {
    username: "admin1",
    password: "12345"
}

function register() {
    let data = fs.readFileSync(__dirname + "/persons.json", "utf8")
    let arr = JSON.parse(data.toString());
    console.log(data, arr);
    let flag = arr.findIndex((v) => {
        return v.username == user.username
    })

    if (flag == -1) {
        arr.push(user)
        fs.writeFileSync(__dirname + "/persons.json", JSON.stringify(arr))
        console.log("注册成功")
    } else {
        console.log("用户名已经被注册")
    }
}
register()